package com.de.demo.client.controller;

import com.de.demo.client.api.UserInfoApi;
import com.de.demo.client.dto.UserInfoDTO;
import com.de.demo.client.param.RegisterParam;
import com.moon.platform.commons.communication.CommunicationFactory;
import com.moon.platform.commons.communication.SimpleResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Base64;


@RestController
@Slf4j
public class UserInfoController {

    @Autowired
    private UserInfoApi userInfoApi;

    @PostMapping("/register")
    public SimpleResponse register(RegisterParam registerParam){
        SimpleResponse simpleResponse = CommunicationFactory.createSimpleResponse();
        Boolean register = userInfoApi.register(registerParam);
        if(register){
            simpleResponse.addData("data","注册成功！！！");
            return simpleResponse;
        }else {
            simpleResponse.addData("data","注册失败！！！");
            return simpleResponse;
        }
    }

    @RequestMapping("/checkLogin")
    public SimpleResponse checkLogin(String account,String password){
        SimpleResponse simpleResponse = CommunicationFactory.createSimpleResponse();
        UserInfoDTO userInfoDTO = userInfoApi.checkUserInfo(account, password);
        if(userInfoDTO.getState()){
            simpleResponse.addData("info","登录成功！欢迎您："+userInfoDTO.getName());
            return simpleResponse;
        }else {
            simpleResponse.addData("info","账号不存在或账号密码错误！");
            return simpleResponse;
        }
    }
}
